package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Dynamic;
import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.service.IDynamicService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.trip.base.domain.Travel;
import cn.wolfcode.trip.base.query.DynamicQueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.IDynamicService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * 朋友圈动态控制器
 */
@RestController
@RequestMapping("dynamics")
public class DynamicController {
    @Autowired
    private IDynamicService dynamicService;

    /**
     * 发朋友圈
      * @param dynamic
     * @return
     */
    @PostMapping
    public JSONResult save(Dynamic dynamic){
        dynamicService.save(dynamic);
        return new JSONResult();
    }
    /**
     * 朋友圈操作
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo query(@ModelAttribute("qo") DynamicQueryObject qo, Model model){
        //按创建时间倒序排列
        return dynamicService.queryDynamicById(qo);
    }
    /**
     * 朋友圈每个人的主页
     * @param qo
     * @return
     */
    @GetMapping("user")
    public PageInfo queryEveryPage(@ModelAttribute("qo") DynamicQueryObject qo, Model model){
        //按创建时间倒序排列
        return dynamicService.queryEveryPage(qo);
    }

    /**
     * 删除朋友圈
     * @param commentId
     * @return
     */
    @DeleteMapping("/delete/{commentId}")
    public JSONResult deleteById(@PathVariable Long commentId){
        dynamicService.deleteById(commentId);
        return new JSONResult();
    }


}
